<?php

namespace app\models;

use think\Model;

/**
 * User: wufeng
 * Date: 2020/02/06.
 */
class ParentInformationModel extends Model
{
    protected $table = 'edu_parent_information';

    /**
     * User: wufeng
     * Date: 2020/03/23.
     *
     * @param $params
     *
     * @throws \think\exception\DbException
     *
     * @return array
     */
    public function getParentInformationLists($params)
    {
        $page = isset($params['page']) ? (int) $params['page'] : 1;
        $listRows = isset($params['limit']) ? (int) $params['limit'] : 10;
        $where = [];
        if (isset($params['status']) && '' !== $params['status']) {
            $where['status'] = $params['status'];
        }
        if (isset($params['username']) && '' !== $params['username']) {
            $where['username'] = $params['username'];
        }
		if(get_current_type() != 1){
			$where['campus_id'] = ['in',get_current_campus_id()];
		}
        $listData = self::where($where)
			->order('id desc')
            ->paginate($listRows, false, ['page' => $page])
            ->toArray();
        if (!empty($listData)) {
            foreach ($listData['data'] as &$item) {
                $item['status_text'] = (1 === (int) $item['status']) ? '启用中' : '禁用中';
                if($item['last_login']){
					$item['last_login'] = date('Y-m-d H:i:s', $item['last_login']);
				}else{
					$item['last_login'] = '-';
				}
				if (1 === (int) $item['img']) {
					$item['img'] = '<img src="'.'/img.jpg'.'" style="width:30px;height:30px; border-radius:15px;">';
				} else {
					$item['img'] = '<img src="'.$item['img'].'" style="width:30px;height:30px; border-radius:15px;">';
				}
            }
        }

        return $listData;
    }
}
